package com.fashionista;

import java.io.InputStream;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.fashionista.getWeather;
import com.fashionista.outfitSelector;
import com.fashionista.wardrobe;

/**
 * A class representing the closet page of the application
 * 
 * @author Trevor Adelman, Patrick Koperwas, Tong Wu, Shayan Yassami
 * @version for cs48 group project, 3/11/2011
 */
public class OutfitActivity extends Activity {
	
	static int shirtNumber =0;
	static int jacketNumber=0;
	static int pantsNumber =0;
	static int shoeNumber  =0;
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.outfit);

        getWeather current = new getWeather();
        try {
			current.setWeather();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		outfitSelector outfit = new outfitSelector();
      
		ClothingParser clothingPars = new ClothingParser();
		InputStream inStr = getResources().openRawResource(R.raw.clothing); //and sets the clothing.xml as the file to be used
		clothingPars.parse(inStr); //Parses the xml file
		wardrobe closet = new wardrobe();
		
		weatherToClothes picker = new weatherToClothes();
		
		final Integer [] JacketId = clothingPars.getJacket(current.returnClothing(current.returnIntDegree()));
		final Integer [] shirtId =  closet.returnShirts();
		final Integer [] PantId  =  clothingPars.getPants(current.returnClothing(current.returnIntDegree()));
		//final Integer [] PantId = closet.returnPants();
		final Integer [] ShoeId  =  closet.returnShoes();
		
		final ImageView iv = (ImageView) findViewById(R.id.shirt_image);
		iv.setImageResource(shirtId[0]);
		
		final ImageView ivJacket = (ImageView) findViewById(R.id.outerLayer_image);
		if(JacketId[0] == null){
			JacketId[0] = R.drawable.jacket_placeholder;
		}
		ivJacket.setImageResource(JacketId[0]);
		
		final ImageView ivPants = (ImageView) findViewById(R.id.pants_image);
		ivPants.setImageResource(PantId[0]);
		
		final ImageView ivShoes = (ImageView) findViewById(R.id.shoes_image);
		ivShoes.setImageResource(ShoeId[0]);
		
		
		
		
		//
		// Buttons for changing jackets
		// Jacket Button right
		//
		Button jacket_right = (Button) findViewById(R.id.button2);
		jacket_right.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(jacketNumber == JacketId.length-1) {
					jacketNumber=0;
					ivJacket.setImageResource(JacketId[jacketNumber]);
					
				}
				else {
				jacketNumber++;
				ivJacket.setImageResource(JacketId[jacketNumber]);	
				}}});
	
		// Jacket Button Left
		Button jacket_left = (Button) findViewById(R.id.button1);
		jacket_left.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(jacketNumber == 0) {
					ivJacket.setImageResource(JacketId[jacketNumber]);
					jacketNumber = JacketId.length-1;
					
				}
				else {
					ivJacket.setImageResource(JacketId[jacketNumber]);
					jacketNumber--;
					
				}}});
		
		// Jacket Select None
		Button jacket_none = (Button) findViewById(R.id.button3);
		jacket_none.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				ivJacket.setImageResource(R.drawable.jacket_placeholder);
				
			}
		});
		
		//
		// Buttons for changing shirts
		// Shirt Button Right
		//
		Button shirt_right = (Button) findViewById(R.id.shirt_right);
		shirt_right.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(shirtNumber == shirtId.length-1) {
					shirtNumber=0;
					iv.setImageResource(shirtId[shirtNumber]);
					
				}
				else {
				shirtNumber++;
				iv.setImageResource(shirtId[shirtNumber]);	
				}}});
		
		// Button shirt left
		
		Button shirt_left = (Button) findViewById(R.id.shirt_left);
		shirt_left.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
			if(shirtNumber == 0) {
				iv.setImageResource(shirtId[shirtNumber]);
				shirtNumber = shirtId.length-1;
				
			}
			else {
				iv.setImageResource(shirtId[shirtNumber]);
				shirtNumber--;
				}}
			});
		
		// Shirt select none
		Button shirt_none = (Button) findViewById(R.id.shirt_none);
		shirt_none.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				iv.setImageResource(R.drawable.jacket_placeholder);
				
			}
		});
		
		//
		// Buttons for changings Pants left
		// Pants Button Left
		//
		Button pants_left = (Button) findViewById(R.id.pants_left);
		pants_left.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(pantsNumber == 0) {
					ivPants.setImageResource(PantId[pantsNumber]);
					pantsNumber = PantId.length-1;
					
				}
				else {
					ivPants.setImageResource(PantId[pantsNumber]);
					pantsNumber--;
					
				}}});
		// Pants Button Right
		Button pants_right = (Button) findViewById(R.id.pants_right);
		pants_right.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(pantsNumber == PantId.length-1) {
					pantsNumber=0;
					ivPants.setImageResource(PantId[pantsNumber]);
					
				}
				else {
				pantsNumber++;
				ivPants.setImageResource(PantId[pantsNumber]);	
				}}});
		
		// Pants Select None
		Button pants_none = (Button) findViewById(R.id.pants_none);
		pants_none.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				ivPants.setImageResource(R.drawable.jacket_placeholder);
				
			}
		});
		
		// Shoes Button Left
		Button shoes_left = (Button) findViewById(R.id.shoesLeft);
		shoes_left.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(shoeNumber == 0) {
					ivShoes.setImageResource(ShoeId[shoeNumber]);
					shoeNumber = ShoeId.length-1;
					
				}
				else {
					ivShoes.setImageResource(ShoeId[shoeNumber]);
					shoeNumber--;
					
				}}});
		
		// Shoes Button Right
		
		Button shoes_right = (Button) findViewById(R.id.shoesRight);
		shoes_right.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(shoeNumber == ShoeId.length-1) {
					shoeNumber=0;
					ivShoes.setImageResource(ShoeId[shoeNumber]);
					
				}
				else {
				shoeNumber++;
				ivShoes.setImageResource(ShoeId[shoeNumber]);	
				}}});
    
		// Shoes Select None

		Button shoes_none = (Button) findViewById(R.id.shoesSelectNone);
		shoes_none.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				ivShoes.setImageResource(R.drawable.jacket_placeholder);
				
			}
		});
    
    }
    }


